package org.jheuristics.ga.operators.selectors;

import java.util.Comparator;

import org.jheuristics.ga.DefaultPopulation;
import org.jheuristics.ga.Population;

/**
 * TODO
 *
 * @author Marcell Manfrin, marcell@ourgrid.org, Dec 22, 2005
 */
public class ComparatorSelector extends BestIndividualsSelector {
	private Comparator comparator;

    /**
     * TODO
     *
     * @param comparator
     */
    public ComparatorSelector(Comparator comparator) {
    	setComparator(comparator);
	}

	/**
	 * TODO
	 *
	 * @see org.jheuristics.ga.operators.selectors.BestIndividualsSelector#sortPopulation(org.jheuristics.ga.Population)
	 * @param population
	 * @return
	 */
	protected Population sortPopulation(Population population) {
    	Population sorted = new DefaultPopulation();
    	sorted.addIndividuals(population);
    	sorted.sort(comparator);
    	return sorted;
	}

	/**
	 * TODO
	 *
	 * @return
	 */
	public Comparator getComparator() {
		return comparator;
	}

	/**
	 * TODO
	 *
	 * @param comparator
	 */
	public void setComparator(Comparator comparator) {
		if (null == comparator) {
			// TODO: ERRO MSG
			throw new NullPointerException();
		}
		this.comparator = comparator;
	}

}
